<html>
<head>
<script language="javascript" type="text/javascript">
var lastTabId = 0;
  var tab_clicks = {};

  chrome.tabs.onSelectionChanged.addListener(function(tabId) {
    lastTabId = tabId;
    chrome.pageAction.show(lastTabId);
  });

  chrome.tabs.getSelected(null, function(tab) {
    lastTabId = tab.id;
    chrome.pageAction.show(lastTabId);
  });

 // Called when the url of a tab changes.
  function checkForValidUrl(tabId, changeInfo, tab) {
    // If the letter 'g' is found in the tab's URL...
    if (tab.url.indexOf('chrome://') == -1) {
      // ... show the page action.
      chrome.pageAction.show(tabId);
    }
  }

  // Listen for any changes to the URL of any tab.
  chrome.tabs.onUpdated.addListener(checkForValidUrl);

  chrome.pageAction.onClicked.addListener(function(tab) {
     var clicks = tab_clicks[tab.id] || 0;
    clicks++;
    tab_clicks[tab.id] = clicks;
   alert(clicks + " :: " + tab.url);
  });

</script>
</head>
</html>